home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 376-400 / disk_386 / xlispstat / src2.lzh / XLisp-Stat / xsscatterpl.c < prev    next >
C/C++ Source or Header  |  1990-10-02  |  3KB  |  126 lines

  1. /* xsscatterplot - XLISP interface to IVIEW dynamic graphics package.  */
  2. /* XLISP-STAT 2.1 Copyright (c) 1990, by Luke Tierney                  */
  3. /* Additions to Xlisp 2.1, Copyright (c) 1989 by David Michael Betz    */
  4. /* You may give out copies of this software; for conditions see the    */
  5. /* file COPYING included with this distribution.                       */
  6.  
  7. #include <string.h>
  8. #include "xlisp.h"
  9. #include "osdef.h"
  10. #ifdef ANSI
  11. #include "xlproto.h"
  12. #include "xlsproto.h"
  13. #include "iviewproto.h"
  14. #include "Stproto.h"
  15. #else
  16. #include "xlfun.h"
  17. #include "xlsfun.h"
  18. #include "iviewfun.h"
  19. #include "Stfun.h"
  20. #endif ANSI
  21. #include "xlsvar.h"
  22.  
  23. /* forward declarations */
  24. #ifdef ANSI
  25. void adjust_variable(IVIEW_WINDOW,int,int *,int *);
  26. LVAL plot2d_add_data(int);
  27. #else
  28. void adjust_variable();
  29. LVAL plot2d_add_data();
  30. #endif ANSI
  31.  
  32. static void adjust_variable(w, var, ticks, labeled)
  33.     IVIEW_WINDOW w;
  34.     int var, *ticks, *labeled;
  35. {
  36.   double low, high;
  37.   char *label;
  38.   
  39.   IViewGetRange(w, var, &low, &high);
  40.   GetNiceRange(&low, &high, ticks);
  41.   IViewSetRange(w, var, low, high);
  42.   label = IViewVariableLabel(w, var);
  43.   *labeled = (label != nil && strlen(label) > 0) ? TRUE : FALSE;
  44. }
  45.  
  46. LVAL iview_plot2d_adjust_to_data()
  47. {
  48.   LVAL object;
  49.   IVIEW_WINDOW w;
  50.   /*char*/ StGWWinInfo *gwinfo; /* changed JKL */
  51.   int x, y, ticks, labeled, scaled;
  52.   LVAL arg;
  53.   
  54.   object = xlgaobject();
  55.   w = GETIVIEWADDRESS(object);
  56.   gwinfo = StGWObWinInfo(object);
  57.   
  58.   if (w != nil) {
  59.     scaled = (slot_value(object, s_scale_type) != NIL) ? TRUE : FALSE;
  60.     StGrGetContentVariables(gwinfo, &x, &y);
  61.     StGrObAdjustToData(object, FALSE);
  62.     ticks = 4;
  63.     if (! scaled) adjust_variable(w, x, &ticks, &labeled);
  64.     IViewSetXaxis(w, ! scaled, labeled, ticks);
  65.     ticks = 4;
  66.     if (! scaled) adjust_variable(w, y, &ticks, &labeled);
  67.     IViewSetYaxis(w, ! scaled, labeled, ticks);
  68.  
  69.     if (! xlgetkeyarg(sk_draw, &arg)) arg = s_true;
  70.     if (arg != NIL) send_message(object, sk_resize);
  71.     if (arg != NIL) send_message(object, sk_redraw);  
  72.   }
  73.   return(NIL);
  74. }
  75.  
  76. static LVAL plot2d_add_data(which)
  77.      int which;
  78. {
  79.   IVIEW_WINDOW w;
  80.   int old_n, n;
  81.   LVAL x, y, data, object;
  82.   
  83.   object = xlgaobject();
  84.   w = GETIVIEWADDRESS(object);
  85.   
  86.   if (w == nil) return(NIL);
  87.     
  88.   xlsave1(data);
  89.   x = xlgetarg();
  90.   if (fixp(x) || (consp(x) && sequencep(car(x)))) data = x;
  91.   else {
  92.     y = xlgetarg();
  93.     data = list2(x, y);
  94.   }
  95.   switch (which) {
  96.   case 'P':
  97.     old_n = IViewNumPoints(w);
  98.     internal_iview_add_points(w, object, data);
  99.     n = IViewNumPoints(w);
  100.     break;
  101.   case 'L':
  102.     old_n = IViewNumLines(w);
  103.     internal_iview_add_lines(w, object, data);
  104.     n = IViewNumLines(w);
  105.     break;
  106. #ifdef USESTRINGS
  107.   case 'S':
  108.     old_n = IViewNumStrings(w);
  109.     internal_iview_add_strings(w, object, data);
  110.     n = IViewNumStrings(w);
  111.     break;
  112. #endif /* USESTRINGS */
  113.   } 
  114.   xlpop();
  115.   
  116.   check_add_to_screen(object, which, old_n, n, FALSE);
  117.   
  118.   return(NIL);
  119. }
  120.  
  121. LVAL iview_plot2d_add_points()   { return(plot2d_add_data('P')); }
  122. LVAL iview_plot2d_add_lines()    { return(plot2d_add_data('L')); }
  123. #ifdef USESTRINGS
  124. LVAL iview_plot2d_add_strings()  { return(plot2d_add_data('S')); }
  125. #endif /* USESTRINGS */
  126.